package com.chisheng.caa.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.chisheng.caa.mapper.CollegeMapper;
import com.chisheng.caa.mapper.TeacherMapper;
import com.chisheng.caa.pojo.dto.TeacherDTO;
import com.chisheng.caa.pojo.entity.College;
import com.chisheng.caa.pojo.entity.Teacher;
import com.chisheng.caa.service.TeacherService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author Chisheng Chen
 */
@Service
public class TeacherServiceImpl implements TeacherService {

    @Resource
    private TeacherMapper teacherMapper;

    @Resource
    private CollegeMapper collegeMapper;

    @Override
    public List<TeacherDTO> getTeacherList() {
        Map<String, String> collegeMap = collegeMapper
                .selectList(null).stream()
                .collect(Collectors.toMap(College::getCollegeId, College::getCollegeName));

        return teacherMapper.selectList(null).stream().map(source -> {
            TeacherDTO dest = new TeacherDTO();
            BeanUtil.copyProperties(source, dest);
            dest.setCollegeName(collegeMap.get(source.getCollegeId()));
            return dest;
        }).collect(Collectors.toList());
    }

    @Override
    public List<String> getTeacherNameList() {
        return teacherMapper.selectList(null).stream().map(Teacher::getTeacherName)
                .collect(Collectors.toList());
    }

}
